package svc

import (
	"context"
	"github.com/huaweicloud/huaweicloud-sdk-go-obs/obs"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"go-zero-demo/app/datacenter/cron/internal/config"
	"go-zero-demo/pkg/gorm/mysql"
	"gorm.io/gorm"
)

type DownloadSvc struct {
	Config config.Config
	RD     *redis.Redis
	DB     *gorm.DB
	//SDKClient *obs.ObsClient
	logx.Logger
}

func NewDownloadSvc(c config.Config) *DownloadSvc {
	// mysql
	db, err := mysql.New(c.MySQL)
	if err != nil {
		panic(err)
	}

	// obs
	//ob, err := newObsClient(c.Obs)
	//if err != nil {
	//	panic(err)
	//}

	return &DownloadSvc{
		Config: c,
		RD:     redis.MustNewRedis(c.Redis),
		DB:     db,
		Logger: logx.WithContext(context.Background()),
		//SDKClient: ob,
	}
}

func newObsClient(cfg config.Obs) (*obs.ObsClient, error) {
	obsInstance, err := obs.New(cfg.AK, cfg.SK, cfg.EndPoint)
	return obsInstance, err
}
